<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>转出</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/fund.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-rollOut-jj">
    <div class="zz-desirable-jj">
        <div class="fl">
            可取<span class="zz-color-jj zz-balance-jj"></span>元至账户余额
        </div>
        <i class="zz-wenhao-jj zz-rollOut-icon-jj" id="zz-prompt-icon-jj"></i>
        <a class="zz-rule-jj" href="../../html/h5/fundRule.html">规则说明</a>
    </div>
    <div class="zz-sumMoney-jj">
        <span class="zz-moneyIcon-jj">￥</span
        >
        <div class="zz-input-jj">
            <input class="zz-moneyInp-jj" id="zz-moneyInp-jj" type="number" placeholder="请输入取出金额" maxlength="10"/>
            <span class="zz-deleteIcon-jj" style="display: none"></span>
        </div>
        <a class="zz-rule-jj" id="zz-allOut-jj" href="javascript:;">全部转出</a>
        <div class="zz-tishi-jj" style="display: none"></div>
    </div>
</div>
<div class="zz-top-20"></div>
<div class="zz-choice-jj">
    <div class="zz-rollOutBtn-jj zz-fast-jj">
        <div class="zz-fastTop-jj zz-fastT-jj">
            <i class="zz-choiceIcon-jj zz-pathIcon-jj" isFast="1">
            </i><span class="zz-fastOut-jj">快速转出</span>
        </div>
        <div class="zz-fastContent-jj">T日发起赎回T日当天到账，T日当天无收益，基金账户最低保留份额0.01元，单日所有货币基金累计上限金额100万元）。</div>
    </div>
    <!-- <div class="zz-rollOutBtn-jj zz-ordinary-jj">
        <div class="zz-fastTop-jj zz-ordinaryT-jj">
            <i class="zz-choiceIcon-jj zz-pathNotIcon-jj" isFast="2">
            </i><span class="zz-fastOut-jj">普通转出</span>
        </div>
        <div class="zz-fastContent-jj">T日发起赎回下一个工作日到账，T日当天继续享有收益。</div>
    </div> -->
</div>

<input class="footer zz-footTop" type="button" value="取出">
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script charset="utf-8" type="text/javascript">
    var $moneyInp = $("#zz-moneyInp-jj");
    var $deleteIcon = $(".zz-deleteIcon-jj");
    var $balance = $(".zz-balance-jj");
    var $tishi = $(".zz-tishi-jj");
    //var $tishi = $(".zz-balance-jj");
    var minRedeemAmount = '';
    var maxRedeemAmt = '';
    var totalAmtFast = "";
    var totalAmt = "";
    var inpAmt = "";
    var mobileId = "";
	var balance = "";
	
    $("#zz-prompt-icon-jj").click(function () {
        new $.modal({
            title: '可取出金额说明',//弹框title
            content: '可取出金额=资产总金额-暂未确认份额金额。T日当天所有申购和赎回在途类订单金额因为尚未确认份额，所以无法取出，（快速取出当天最大金额上限为100万元，普通取出可全部取出）',//弹框内容
//            serviceCharge:"服务费￥100元，到账金额3433元",
            confirm: "确定",
            isshowclosebtn: false,//是否显示取消按钮
            showcontent: false,//false为弹出框组件二，true为弹出框组件一
            closecallback: function () {
            },//点击关闭时触发事件
            surecallback: function () {
                //点击确定时触发事件
            }
        }).show();
    });

    //初始化页面数据
    $.ajax({
        url: utils.ajaxUrl()+"h5/fund/opendAccount/initRedeem",
        async: false,
        type: 'get',
        success: function (res) {
            var res = JSON.parse(res);
            console.log(res);
            if (res && res.retCode == '0000') {
                minRedeemAmount = utils.removeSpace(res.minRedeemAmount,",");
                maxRedeemAmt = utils.removeSpace(res.maxRedeemAmt,",");
                balance = utils.removeSpace(res.balance,",");
                mobileId = res.mobileId;
                if(parseFloat(balance) > 1000000){
                    totalAmtFast = utils.comma(parseFloat(balance).toFixed(2));
                }else if (parseFloat(balance) < 0.01){
                	totalAmtFast = "0.00"
                }else{
                    totalAmtFast = utils.comma((parseFloat(balance) - 0.01).toFixed(2));
                }
                if(parseFloat(balance) < parseFloat(maxRedeemAmt)){
                    inpAmt = balance
                }else{
                    inpAmt = maxRedeemAmt
                }
                totalAmt = utils.comma(balance);
                $balance.html(totalAmtFast);
            } else {
                utils.error("sx.png", "啊哦，数据异常");
            }
        },
        error: function () {
            utils.error("wlyc.png", "啊哦，连接不到网络呢");
        }
    });

    if ($moneyInp.val().length > 0) {
        if ($(".zz-pathIcon-jj").attr("isfast") == 1) {
            inpIf($moneyInp.val());
        }
        $moneyInp.css("font-size", ".6rem").removeAttr("placeholder");
        $deleteIcon.show();
    }

    $moneyInp.focus(function () {
        var that = $(this);
        that.css("font-size", ".6rem").removeAttr("placeholder");
        $tishi.html("").hide();
    });

    $moneyInp.blur(function () {
        var that = $(this);
        var inpNum = that.val();
        if (inpNum.length == 0) {
            that.val("");
            that.css("font-size", ".3rem").attr("placeholder", "请输入取出金额");
            $tishi.html("请输入正确取出金额").show();
            $deleteIcon.hide();
            return false;
        } else {
            $deleteIcon.show();
        }

        var inpVal = inpNum.split(".");
        if (inpVal[1]) {
            that.val(inpVal[0] + "." + inpVal[1].slice(0, 2))
        }

        if ($(".zz-pathIcon-jj").attr("isfast") == 1) {
            inpIf(inpNum);
        }

        if (parseFloat(that.val()) > parseFloat(utils.removeSpace($balance.html(),","))) {
            that.val(utils.removeSpace($balance.html(),","))
        }
    });

    $("#zz-allOut-jj").click(function () {
        var balance = utils.removeSpace($balance.html(),",");
        $moneyInp.val(balance).css("font-size", ".6rem");
        $deleteIcon.show();
        if ($(".zz-pathIcon-jj").attr("isfast") == 1) {
            inpIf(balance);
        } else {
            $tishi.html("").hide();
        }
    });

    $deleteIcon.click(function () {
        $moneyInp.val("").css("font-size", ".3rem").attr("placeholder", "请输入取出金额");
        $deleteIcon.hide();
        $tishi.hide();
    });

    $(".zz-fastTop-jj").click(function () {
        var that = $(this);

        if (that.hasClass("zz-fastT-jj")) {
            inpIf($moneyInp.val());
            $balance.html(totalAmtFast);
            if ($moneyInp.val() > parseFloat(utils.removeSpace($balance.html(),","))) {
                $moneyInp.val(utils.removeSpace($balance.html(),","));
            }

            if (!that.children(".zz-choiceIcon-jj").hasClass("zz-pathIcon-jj")) {
                that.children(".zz-choiceIcon-jj").addClass("zz-pathIcon-jj").removeClass("zz-pathNotIcon-jj");
                $(".zz-ordinaryT-jj").children(".zz-choiceIcon-jj").addClass("zz-pathNotIcon-jj").removeClass("zz-pathIcon-jj");
            }
        }
        if (that.hasClass("zz-ordinaryT-jj")) {
            $tishi.hide();
            $balance.html(totalAmt);
            if ($moneyInp.val().length == 0) {
                $tishi.html("请输入正确取出金额").show();
                $deleteIcon.hide();
            }
            if (!that.children(".zz-choiceIcon-jj").hasClass("zz-pathIcon-jj")) {
                that.children(".zz-choiceIcon-jj").addClass("zz-pathIcon-jj").removeClass("zz-pathNotIcon-jj");
                $(".zz-fastT-jj").children(".zz-choiceIcon-jj").addClass("zz-pathNotIcon-jj").removeClass("zz-pathIcon-jj");
            }
        }
    });

    function inpIf(val) {
        if (parseFloat(val) < parseFloat(minRedeemAmount)) {
            $tishi.html("快速取出最小金额为" + minRedeemAmount + "元").show();
            return false;
        } else if (parseFloat(val) > parseFloat(maxRedeemAmt)) {
            $tishi.html("T+0赎回单天取出金额暂时最大支持100万元").show();
            $moneyInp.val(inpAmt);
            return false;
        } else {
            $tishi.html("").hide();
            return true;
        }
    }

    $footer.click(function () {
        var inpNum = $moneyInp.val();
        if (inpNum == "") {
            $moneyInp.val("").css("font-size", ".3rem").attr("placeholder", "请输入取出金额");
            $tishi.html("请输入正确取出金额").show();
            return false;
        }
        if ($(".zz-pathIcon-jj").attr("isfast") == 1) {
            console.log(inpIf(inpNum));
            if (!inpIf(inpNum)) {
                return false
            }
        }
        if (parseFloat($moneyInp.val()) > parseFloat(utils.removeSpace($balance.html(),","))) {
            $tishi.html("请输入正确取出金额").show();
            return false
        }
        if (!utils.decimalPlaces(inpNum, $footer, "请输入正确取出金额")) {
            //$tishi.html("请输入正确金额").show();
            return false;
        }
        var isFast = $(".zz-pathIcon-jj").attr("isFast");

        window.location.href = "../../html/h5/fundMsgVerify.html?page=fundRollOut&origAmt="+inpNum+"&isFast="+isFast+"&mobileId="+mobileId;
    });

</script>
</html>